package yxy.game.pm2.bean.currency;

import java.util.ArrayList;
import java.util.Collection;

import yxy.game.pm2.bean.Currency;

/** Currency的集合封装 */
public class Currencies extends ArrayList<Currency> {

	private static final long serialVersionUID = 1L;

	public Currencies() {
	}

	public Currencies(Collection<Currency> currencys) {
		add(currencys);
	}

	public Currencies(Currency currency) {
		add(currency);
	}

	@Override
	public boolean add(Currency currency) {
		if (currency == null) {
			return false;
		}
		String code = currency.code();
		if (!currency.getType().equals(CurrencyType.CT_武将)) {
			for (Currency c : this) {
				if (c.code().equals(code)) {
					c.setNumber(c.getNumber() + currency.getNumber());
					return true;
				}
			}
		}
		return super.add(currency);
	}

	public boolean add(Collection<Currency> currencys) {
		return addAll(currencys);
	}

	@Override
	public boolean addAll(Collection<? extends Currency> currencys) {
		for (Currency currency : currencys) {
			if (currency.getNumber() <= 0) {
				continue;
			}
			add(currency);
		}
		return true;
	}
}
